package com.system.healthproject.model.sickuser.controller;

import com.system.healthproject.annotation.RequireToken;
import com.system.healthproject.common.ApiResult;
import com.system.healthproject.model.admin.paramsbean.LoginParams;
import com.system.healthproject.model.admin.paramsbean.VisitRecordsParams;
import com.system.healthproject.model.sickuser.service.VisitRecordsService;
import com.system.healthproject.pojo.VisitRecords;
import com.system.healthproject.utils.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(value = "患者端-就诊记录",tags = "患者端-就诊记录API")
@RestController
@RequestMapping("/sickuser/visitRecords")
public class UserVisitRecordsController {
    @Autowired
    VisitRecordsService visitRecordsService;
    @Autowired
    RedisUtil redisUtil;


    @RequireToken
    @ApiOperation(value = "新增就诊记录(后端已调)",notes = "新增就诊记录",httpMethod = "post")
    @PostMapping(value = "/addVisitRecords",produces = "application/json;charset=utf-8")
    public ApiResult addVisitRecords(@Validated @RequestBody @ApiParam(required = true)
                                                 VisitRecordsParams addRecordParamss,
                                     @RequestHeader("token")String token){
        Map<String, Object> map = (Map<String, Object>) redisUtil.get(token);
        Integer loginId = (Integer) map.get("loginId");
        boolean b = visitRecordsService.addVisitRecords(addRecordParamss, loginId);
        return ApiResult.withBoolean(b,"新增就诊记录成功","新增就诊记录十八");
    }
}
